package cn.chenhongchao.hospital.service.impl;

import cn.chenhongchao.hospital.entity.Medicine;
import cn.chenhongchao.hospital.entity.MedicineExample;
import cn.chenhongchao.hospital.mapper.MedicineMapper;
import cn.chenhongchao.hospital.service.IMedicineService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 啊超
 * @time: 2021/6/17 22:13
 */
@Service
public class MedicineServiceImpl implements IMedicineService {
    @Resource
    private MedicineMapper medicineMapper;

    @Override
    public List<Medicine> list() {
        MedicineExample example = new MedicineExample();
        return medicineMapper.selectByExample(example);
    }

    @Override
    public Medicine getMedicineById(Long id) {
        return medicineMapper.selectByPrimaryKey(Long.toString(id));
    }

    @Override
    public List<Medicine> getMedicineByName(String drugName) {
        MedicineExample example = new MedicineExample();
        MedicineExample.Criteria criteria = example.createCriteria();

        if(!StringUtils.isEmpty(drugName)) {
            criteria.andMedicineNameLike("%" + drugName + "%");
        }
        return medicineMapper.selectByExample(example);

    }


}
